<template>
  <div class="app-container">
    <el-page-header @back="goBack" content="" class="mb8"></el-page-header>
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="用户ID、用户名：" prop="userInfo">
        <el-input
            v-model="queryParams.userInfo"
            placeholder="请输入用户ID、用户名"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row type="flex" justify="space-between" class="mb8">
      <el-col :span="6" class="tag-group">
        <el-tag v-for="(item, index) in tagItems" :key="item.label"
          :effect="queryParams.levelType === item.value ? 'dark' : 'plain'" style="margin-right: 10px"
          @click="handleClick(item)">
          {{ item.label }}
        </el-tag>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="tenantList">
      <el-table-column label="编号" align="center" prop="id" sortable />
      <el-table-column label="所属层级" align="center" prop="levelType">
        <template slot-scope="scope">
          <span>{{ scope.row.levelType === 1 ? '一级' : '二级' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center" prop="userId" />
      <el-table-column label="用户名" align="center" prop="userName" />
      <el-table-column label="邀请人数" align="center" width="110" prop="inviteNum" sortable />
      <el-table-column label="消费金额(元)" align="center" width="120" prop="consumerMoney" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.consumerMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column label="累计收益(元)" align="center" width="120" prop="totalEmployee" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.totalEmployee }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已提现(元)" align="center" width="120" prop="haveWithdraw" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.haveWithdraw }}</span>
        </template>
      </el-table-column>
      <el-table-column label="收益余额(元)" align="center" width="120" prop="employeeRetain" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.employeeRetain }}</span>
        </template>
      </el-table-column>
      <el-table-column label="提现申请(元)" align="center" width="120" prop="withdrawApplication" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.withdrawApplication }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上级收益余额(元)" align="center" width="150" prop="firstLevelEmployeeRetain" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.firstLevelEmployeeRetain }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上上级收益余额(元)" align="center" width="170" prop="secondLevelEmployeeRetain" sortable>
        <template slot-scope="scope">
          <span>￥{{ scope.row.secondLevelEmployeeRetain }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
import { getExtendDetail } from "@/api/shuiyin/shuiyin";

export default {
  name: "Classification",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分类表格数据
      tenantList: [],
      // 查询参数
      queryParams: {
        userId: null,
        userInfo: null,
        levelType: '',
        pageNum: 1,
        pageSize: 10,
      },
      tagItems: [
        {
          value: '',
          label: '全部'
        }, {
          value: '1',
          label: '一级'
        }, {
          value: '2',
          label: '二级'
        }
      ],
    };
  },
  created() {
    const type = this.$route.params && this.$route.params.type;
    if (type) {
      this.queryParams.userId = type;
      this.getList();
    }
  },
  methods: {
    /** 查询租户管理列表 */
    getList() {
      this.loading = true;
      getExtendDetail(this.queryParams).then(response => {
        this.tenantList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // tag标签点击事件
    handleClick(item) {
      this.queryParams.levelType = item.value;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 返回 */
    goBack() {
      this.$store.dispatch("tagsView/delView", this.$route);
      // 1. 模板管理 2. 背景管理 3.贴图管理 4.数字人管理 5.音乐管理 6.主播管理
      this.$router.push({ path: "/extend/information" });
    }
  }
};
</script>
